import unittest
import os
from common import HTMLTestReportCN
from common.log_utils import logger
from common.email_utils import EmailUtils

logger.info("创建报告路径")
current_path = os.path.dirname(__file__)
case_path = os.path.join( current_path , 'testcase')
discover_cases = unittest.defaultTestLoader.discover(start_dir=case_path,
                                                     pattern='tests*.py')
logger.info("将测试用列加到测试套件中")
case_suite = unittest.TestSuite()
case_suite.addTest( discover_cases )

logger.info("报告的路径和报告文件的创建")
html_report_path = os.path.join( current_path , 'html_reports/')
report_path=HTMLTestReportCN.ReportDirectory( html_report_path )
report_path.create_dir('WX_TEST_API_')
logger.info("获取报告的文件")
html_report_file_path=HTMLTestReportCN.GlobalMsg.get_value('report_path')
fp = open(html_report_file_path,'wb')
runner = HTMLTestReportCN.HTMLTestRunner(stream=fp,
                                         title="微信公众号平台测试",
                                         tester="李红英",
                                         description="接口自动化测试")
runner.run(discover_cases)

email_body='''
    <h1 align="center">接口自动化测试报告56 </h1>
    <p align="center">详情请见附件</p>
'''
EmailUtils(email_body).send_email()


# if __name__=='__main__':
#     current_path=os.path.dirname(__file__)
#     discover= unittest.defaultTestLoader.discover(current_path,'tests_*.py')
#     suite=unittest.TestSuite()
#     suite.addTest(discover)
#     runner=unittest.TextTestRunner()
#     runner.run(discover)











